\documentclass[a4paper,12pt]{article}
\usepackage{color}
% \usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage{latexsym}
\usepackage{amssymb}
% \usepackage{polski}
% \usepackage[polish]{babel}
%\usepackage{a4wide}
% wstawianie obrazkow
%\usepackage{graphicx}
%\usepackage{subfig}

%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amsthm}

%\pagestyle{fancy}

%\pagestyle{fancy}

\renewcommand{\headheight}{16pt}

\newcommand{\HRule}{\rule{\linewidth}{0.1mm}}

\begin{document}

%\begin{titlepage}
\begin{center}
%	\textsc{1}\\
%	\textsc{2}\\[4cm]
% 	\HRule\\
%	\HRule \\[2cm]
	\textsc{\Large Distributed Database Systems (WS 11/12) }\\[0.3cm]
	\textsc{\large Assignment 2}\\[1cm]
        Adam Grycner\\
        Szymon Matejczyk\\[1cm]
        \today\\[1cm]
 	\HRule\\
%	\HRule\\[2cm]
	
\end{center}

\section{Exercise 2.1: Relational Algebra}
\begin{enumerate}[(a)]
 \item  
 \begin{enumerate}[1.]
  \item Incorrect
    \begin{itemize}
     \item We don't know if 'firstName' and 'lastName' are defined over the same domain so it could be not possible to make union.
     \item $\sigma_{year < 2001}$ need the 'year' attribute, which is not placed in table $\pi_{firstName}(Person) \cup \pi_{lastName}(Person)$.
    \end{itemize}
  \item Correct (People, whose last name is 'Saarbr.')
 \end{enumerate}

 \item
 \begin{enumerate}[1.]
  \item $\pi_{PID, lastName, age}(\sigma_{age < 25}(Person) )$
\begin{verbatim}
select distinct PID, lastName, age 
from Person 
where age < 25;
\end{verbatim}

  \item $\pi_{city}( \sigma_{reason = 'broken\ windshield'}( Mechanic \Join Repairs ) )$
\begin{verbatim}
select distinct m.city 
from Mechanic m, Repairs r 
where m.PID = r.PID and reason == "broken windshield" ;
\end{verbatim}

  \item $\pi_{firstName, age}( \sigma_{model = 'Audi\ A1'\ and\ date = 'October\ 26,\ 2011'}(Car \Join Repairs \Join Mechanic \Join Person) ) $
\begin{verbatim}
select distinct p.firstName, p.age
from  Car c, Repairs r, Mechanic m, Person p
where r.PID = p.PID and m.PID = p.PID and r.CID = c.CID
and c.model = "Audi A1" and r.date = "October 26, 2011";
\end{verbatim}

 \item $\pi_{CID}( (Owns \ltimes_{ Owns.CID = Owns.CID} Owns) \setminus Owns ) $
\begin{verbatim}
SELECT CID FROM
  (SELECT * FROM  Owns o1 LEFT JOIN Owns o2 ON o1.CID = o2.CID)
    MINUS
  (SELECT * FROM Owns);
\end{verbatim}

 \end{enumerate}
\end{enumerate}

\section{Exercise 2.2: Discussion}
\begin{enumerate}[(a)]
 \item  
 \begin{enumerate}[1.]
   \item Fragmentation \\
   Decomposing relations into smaller, disjunctive elements.
   \item Allocation \\
   Distributing fragmented fragments of relations across nodes.
 \end{enumerate}
 \item
   Fragmentation violates completeness rule, when it does not contain all data.
 \item
   Disjointness is important, because it enables to process query independently on different fragments.
 \item Criteria important for good fragmentation and allocation:
   \begin{itemize}
   \item communication cost
   \item availability
   \item load balancing
   %storage cost
   %transfer cost
   \end{itemize}
 \item Replication
   \begin{itemize} 
     \item Advantages of replication
       \begin{enumerate}
       \item Higher availability
       \item Shorter average read time
       \item Lower risk of data loss
       \end{enumerate}
     \item Disadvantages of replication
       \begin{enumerate}
       \item Loss in write performance (need to synchronize replicas)
       \item Higher storage need
       \end{enumerate}
     \item Cases in which full replication is profitable
       \begin{enumerate}
         \item significantly more read than write operations
         \item very fast worst response time needed on read
       \end{enumerate}
   \end{itemize}
\end{enumerate}


\end{document}
